package rs.creator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import rs.domain.RecommendedTrack;
import rs.domain.Tag;
import rs.domain.Track;
import rs.thread.MultiThreadWorker;
import rs.thread.processor.RecommendedTrackProcessor;
import rs.util.Requester;
import rs.util.RecommendedTrackComparator;

/* Classe responsabile di creare la lista dei brani da raccomandare all'utente.
 * I brani saranno ordinati per rilevanza rispetto ai best tag.
 * Il task in questione prevede l'uso di più thread. */
public class RecommendedTracksListCreator {
	
	public List<RecommendedTrack> create(Requester app, List<Tag> tag_list) {
		RecommendedTrackProcessor ttp = new RecommendedTrackProcessor();
		MultiThreadWorker<Tag> mtw = new MultiThreadWorker<Tag>();
		mtw.compute(ttp, tag_list);
		Map<Track, Double> track2rating =  ttp.getResult();
		
		List<RecommendedTrack> track_list = new ArrayList<RecommendedTrack>();		
		for (Track t : track2rating.keySet()) {
			track_list.add(new RecommendedTrack(t, track2rating.get(t)));
		}
		Collections.sort(track_list, new RecommendedTrackComparator());
		
		return track_list;
	}

}
